using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework.Domain.Effectivity
{
    /// <summary>
    /// AssertEffectivities makes it easier to write assertions on instances of Effectitivy.
    /// </summary>
    public static class AssertEffectivities
    {
        /// <summary>
        /// Assert that the given effectivities are equal.
        /// Effectivities are equal when they:
        /// - are of the same type,
        /// - have equal elements,
        /// - have equal validityperiods.
        /// </summary>
        /// <typeparam name="T">The type of the Element</typeparam>
        /// <param name="expectedEffectivity"></param>
        /// <param name="actualEffectivity"></param>
        public static void AreEqual<T>(IEffectivity<T> expectedEffectivity, IEffectivity<T> actualEffectivity)
        {
            Assert.AreEqual(expectedEffectivity.GetType(), actualEffectivity.GetType());
            Assert.AreEqual(expectedEffectivity.Element, actualEffectivity.Element);
            Assert.AreEqual(expectedEffectivity.Period.Begin.ToString("yyyy-MM-dd-HH:mm:ss"), actualEffectivity.Period.Begin.ToString("yyyy-MM-dd-HH:mm:ss"));
            Assert.AreEqual(expectedEffectivity.Period.End.ToString("yyyy-MM-dd-HH:mm:ss"), actualEffectivity.Period.End.ToString("yyyy-MM-dd-HH:mm:ss"));
        }

        /// <summary>
        /// Assert that the given lists of effectivities are equal.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="expected"></param>
        /// <param name="actual"></param>
        public static void AreEqual<T>(IList<IEffectivity<T>> expected, IList<IEffectivity<T>> actual)
        {
            Assert.AreEqual(expected.Count, actual.Count);
            for(int i = 0; i < expected.Count; ++i)
            {
                if(expected[i] == null && actual[i] == null)
                {
                    break;
                }

                AreEqual(expected[i], actual[i]);
            }
        }
    }
}